package com.oa.service.impl;

import com.oa.vo.Page;
import com.oa.pojo.Subject;
import com.oa.mapper.SubjectMapper;
import com.oa.service.SubjectService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SubjectServiceImpl implements SubjectService {

    @Autowired
    SubjectMapper subjectMapper;

    @Override
    public void addSubject(Subject subject) {
        subjectMapper.addSubject(subject);
    }

    @Override
    public void delSubject(Integer subjectId) {
        subjectMapper.delSubject(subjectId);
    }

    @Override
    public void updateSubject(Subject subject) {
        subjectMapper.updateSubject(subject);
    }

    @Override
    public List<Subject> getSubjectList() {
        return subjectMapper.getSubjectList();
    }

    @Override
    public Page getSubjectPage(Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<Subject> subjectList = subjectMapper.getSubjectList();
        Page page = new Page();
        PageInfo<Subject> pageInfo = new PageInfo<>(subjectList);
        page.setPageCount(pageInfo.getPages());
        page.setCount(pageInfo.getTotal());
        page.setObject(pageInfo.getList());
        return page;
    }

    @Override
    public Subject getSubject(Integer subjectId) {
        return subjectMapper.getSubject(subjectId);
    }
}
